package cn.miketsu.util;

import cn.miketsu.App;
import org.apache.commons.lang3.StringUtils;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author 王泽风
 * @date 2021/11/13
 */
public class ConfigUtils {

    public static String getProperties(String key) throws Exception {
        Properties prop = new Properties();
        InputStream inputStream = new FileInputStream(App.file);
        prop.load(inputStream);
        String property = prop.getProperty(key);
        if (StringUtils.isBlank(property)) {
            System.out.println("读取配置文件失败！");
            System.exit(0);
        }
        return property;
    }

    public static String getPropertiesIgnoreBlank(String key) throws Exception {
        Properties prop = new Properties();
        InputStream inputStream = new FileInputStream(App.file);
        prop.load(inputStream);
        String property = prop.getProperty(key);
        return StringUtils.isNotBlank(property) ? property : "";
    }
}
